package com.awesome.spring.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.awesome.spring.bean.Account;
import com.awesome.spring.mapper.AccountMapper;
import com.awesome.spring.service.AccountService;
import io.seata.core.context.RootContext;
import org.springframework.stereotype.Service;

/**
 * AccountServiceImpl
 *
 * @author alex wu
 * @date 2023/10/13
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public String reduce(String userId, int money) {
        String xid = RootContext.getXID();
        System.out.println(xid);
        UpdateWrapper<Account> up = new UpdateWrapper<>();
        String sql = "money = money - " + money;
        up.setSql(sql);
        up.eq("user_id", userId);
        this.update(up);
        return "ok";
    }
}
